#include<stdio.h>
#include<stdlib.h>
#include<sys/mman.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>

int main()
{
    const int SIZE = 4096;

    //创建共享文件
    const char *fileName = "os";
    int fd = shm_open(fileName, O_CREAT|O_RDWR, 0666);

    //设置文件大小
    ftruncate(fd, SIZE);

    //映射到进程地址空间
    void* ptr = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, fd, 0);

    //发消息
    const char*message = "我们是同志了";
    sprintf(ptr, "%s", message);
    ptr += strlen(message);

    printf("按任意键退出\n");
    char ch = getchar();
}